import Vue from 'vue'
import Router from 'vue-router'
import axios from '../axios'

import admin from '@/components/admin'

import index from '@/components/index'

import hotel from '@/components/hotel'

import edit_hotel from '@/components/hotel/edit.vue'

import ticket from '@/components/ticket/'

import edit_ticket from '@/components/ticket/edit.vue'

import login from '@/components/login'

import strategy from '@/components/strategy/index'
import strategy_Upda from '@/components/strategy/upda'

import scenic from '@/components/scenic/index'
import scenic_edit from '@/components/scenic/edit'

import user from '@/components/user/index'

Vue.use(Router)

const routes=[
  {
    path: '/admin',
    name: 'admin',
    component: admin,
    children:[
      {path:'/',component:index},
      {path:'strategy',component:strategy},
      {path:'strategy_Upda',component:strategy_Upda},
      {path:'scenic',component:scenic},
      {path:'scenic_edit',component:scenic_edit},
      {path:'hotel',component:hotel},
      {path:'edit_hotel',component:edit_hotel},
      {path:'ticket',component:ticket},
      {path:'edit_ticket',component:edit_ticket},
      {path:'strategy',component:strategy},
      {path:'strategy_Upda',component:strategy_Upda},
      {path:'scenic',component:scenic},
      {path:'scenic_edit',component:scenic_edit},
<<<<<<< HEAD
      {path:'user',component:user}
=======
      {path:'user',component:user},
      {path:'edit_ticket',component:edit_ticket}
      
>>>>>>> 929b7f2e456f975d4d8602f18435a3d0a6bbdada
    ]
  },
  {
    path:'/login',name:'登录',component:login
  }
]

const route = new Router({
  routes
})

route.beforeEach((to, from, next) => {

  if(to.path=='/'){

    next('/admin')

  }

  axios.post('/admin.php/login/check_login').then( (res) => {

    if(res.data.code==1){

      Vue.prototype.$userInfo=res.data.data

      if(to.path=='/login'){
        next('/admin')
      }else{
        next()
      }

    }else{

      if(to.path!='/login'){
        next('/login')
      }else{
        next()
      }
<<<<<<< HEAD

=======
      
>>>>>>> 929b7f2e456f975d4d8602f18435a3d0a6bbdada
    }
  } ).catch( (err) => {
    next('/login')
  } )
})

export default route
